import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 * User: zm
 * Date: 2023/5/6
 */
public class Demo26 {
    static int[] e = new int[100010];
    static int[] ne = new int[100010];
    static int head;
    static int idx;
    //初始化
    public static void init(){
        head = -1;
        idx = 0;
    }
    //向头节点添加元素
    public static void addHead(int x){
        e[idx] = x;
        ne[idx] = head;
        head = idx++;
    }
    //想k位置后面添加元素
    public static void add(int k, int x){
        e[idx] = x;
        ne[idx] = ne[k];
        ne[k] = idx++;
    }
    public static void remove(int k){
        ne[k] = ne[ne[k]];
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int m = scan.nextInt();
        init();
        while(m -- > 0){
            String s = scan.next();
            char op = s.charAt(0);
            if(op == 'H'){
                int x = scan.nextInt();
                addHead(x);
            }else if(op == 'D'){
                int k = scan.nextInt();
                if(k == 0)head =  ne[head];
                else remove(k - 1);
            }else {
                int k = scan.nextInt();
                int x = scan.nextInt();
                add(k - 1, x);
            }
        }
        for(int i = head; i != -1; i = ne[i]){
            System.out.print(e[i] + " ");
        }
    }
}
